// 微信登录和授权
import request from '../axios'
var qs = require('qs')
const requestLogin = (data) => {
  // if (localStorage.accToken) return
  return request({
    url: `/socials/weixin/authorizations`,
    method: 'post',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
// 获取code
const requstWechatAuth = (data) => {
  // console.log(encodeURIComponent(location.href), 'encodeURIComponent(location.href)')
  let url = new URL(location.href)
  // debugger
  let code = url.searchParams.get('code')
  return request({
    // url: '/generate/wechatauthlink?redirect_url=' + encodeURIComponent(location.href),
    // code ? encodeURIComponent(location.href.replace('code=', '&ode=')) :
    url: '/generate/wechatauthlink?redirect_url=' + encodeURIComponent(location.href.replace('code=', '&ode=')),
    method: 'get',
    params: data
  })
}

export default { requestLogin, requstWechatAuth }
